// app.js
// test
// 执行utils/utils.js代码
import './utils/utils'
// 执行一下 http.js代码修改了代码
import './utils/http'
App({
  globalData: {},
  token: '',
  refresh_token: '',
  onLaunch () {
    // 获取token和refresh_token
    this.getToken('token')
    this.getToken('refresh_token')
  },
  // 设置本地token及refresh_token
  setToken (token, refresh_token) {
    // 接口成功了 设置本地的token Bearer后面有一个空格
    token = 'Bearer ' + token
    refresh_token = 'Bearer ' + refresh_token
    // 存在app上
    this.token = token
    this.refresh_token = refresh_token
    // 把token和refresh_token放在本地缓存上
    wx.setStorageSync('token', token)
    wx.setStorageSync('refresh_token', refresh_token)
  },
  // 读取本地的数据
  getToken (key) {
    wx.getStorage({
      key,
      success: (res) => {
        console.log(key, res)
        this[key] = res.data
      }
    })
  },
  // 读取本地的refresh_token
  // getRefreshToken () {
  //   wx.getStorage({
  //     key: 'refresh_token',
  //     success: (res) => {
  //       console.log('refresh_token', res)
  //       this.refresh_token = res.data
  //     }
  //   })
  // }
})
